<?php
/**
 * AEntity abstarct entity classes
 * @package Core
 * @subpackage Entity
 * @category Abstract
 * @author kovacsricsi
 */
abstract class AEntity {

	/**
	 * Data of entity.
	 * @access protected
	 * @var array
	 */
	protected $_entity;

	/**
	 * Constructor.
	 * @access public
	 * @param int $id
	 * @return void
	 */
	public function __construct($id = null)
	{
		$this->_entity = array();

		if ($id) {
			$this->_load($id);
		}
	}

	/**
	 * __get
	 * @access public
	 * @param string $key
	 * @return string
	 */
	public function __get($key)
	{
		if (isset($this->_entity[$key])) {
			return $this->_entity[$key];
		} else {
			return null;
		}
	}

	/**
	 * __set
	 * @access public
	 * @param string $key
	 * @param string $value
	 * @return void
	 */
	public function __set($key, $value)
	{
		if ($key != "id") {
			$this->_entity[$key] = $value;
		}
	}

	/**
	 * Load entity from database.
	 * @access protected
	 * @param int $id
	 * @return void
	 */
	abstract protected function _load($id);

	/**
	 * Delete entity from database.
	 * @access public
	 * @return void
	 */
	abstract public function delete();

	/**
	 * Store entity to database.
	 * @access public
	 * @return void
	 */
	abstract public function commit();

	/**
	 * Validate data to store entity.
	 * @access public
	 * @return void
	 */
	 abstract public function validate();
}

?>